<?php
/**
 *
 *手机站商品页
 *
 * @copyright  Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');

class goodsControl extends MobileControl{
	
	const XIANSHI_STATE_PUBLISHED = 2;
    const XIANSHI_STATE_END = 5;
    const XIANSHI_GOODS_STATE_NORMAL = 1;
    const MANSONG_STATE_PUBLISHED = 2;
	
	public function __construct(){
		parent::__construct();
	}
	
	//商品分类页
	public function goods_classOp(){
		
		$goods_class = F('goods_class');
		$new_gc = array();
		foreach($goods_class as $key=>$val){
			if($val['gc_parent_id'] == 0){
				$subCls = explode(',',$val['child']);
				foreach($subCls as $id){
					$new_gc[$id] = $goods_class[$id];
					foreach(explode(',',$goods_class[$id]['child']) as $sid){
						$new_gc[$id]['subClass'][] = $goods_class[$sid];
					}	
				}
			}
		}
		Tpl::output('goods_class',$new_gc);
		Tpl::showpage('goods_class');
	}
	
	/**
	 * 单个商品信息页
	 *
	 */
	public function indexOp() {
                  if($_GET['goods_id'] == 30513){
                      $user_agent = $_SERVER['HTTP_USER_AGENT'];
                      if (strpos($user_agent, 'MicroMessenger') === false) {
                          
                      }else{
                            @header('Location:http://www.d1vz.com');
                      }
                 }
		//$c= '\u6d88';
		//echo $c=preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4','\\1'))", $c);die;
		
		if(empty($_GET['goods_id']))mobileJump('缺少参数');//"缺少参数:商品编号"
		$goods_id	= intval($_GET['goods_id']);
		//imsModel::autoSyncGoods($goods_id);
		$model_store_goods	=new goodsModel();
		//$goods_array = $model_store_goods->getGoods(array('goods_id'=>intval($_GET['goods_id'])),'','goods.*,goods_spec.spec_goods_storage');
		$goods_array = $model_store_goods->where(array('goods_id'=>intval($_GET['goods_id'])))->find();
		//echo '<pre>';print_r($goods_array);die;
		// 验证商品是否存在
		if(empty($goods_array) || $goods_array['goods_store_state'] == 1 )mobileJump('商品已下架或不存在');

        if($goods_array['gds_id'] != '0'){
            $sql = "SELECT * FROM #__goods_detail_set WHERE is_show = '1' AND gds_id IN({$goods_array['gds_id']}) ORDER BY gds_sort ASC";
            $gds = DB::queryAll($sql);
            Tpl::output('gds',$gds);
        }
		//获取商城信息
		$store_info = $this->getStoreInfo($goods_array['store_id']);
	
		$_GET['id']	= $goods_array['store_id'];
		//得到商品规格
		$spec_array	= $model_store_goods->getSpecGoods($goods_array['goods_id']);
		if(empty($spec_array)) {
			mobileJump('商品已下架或不存在');
		}
		if(!empty($spec_array) && is_array($spec_array)){
            $goods_storage_total=0;//商品总库存
			foreach ($spec_array as $key => $val){
                $goods_storage_total+=$val['spec_goods_storage'];
				$s_array	= unserialize($val['spec_goods_spec']);
				$val['spec_goods_spec']	= '';
				if(!empty($s_array) && is_array($s_array)){
					foreach ($s_array as $k=>$v){
						$val['spec_goods_spec'] .= "'".$k."',";
					}
				}
				$val['spec_goods_spec']	= rtrim($val['spec_goods_spec'],',');
				//将商品默认规格的库存复制到商品数组中
				if ($val['spec_id'] == $goods_array['spec_id']){
					$goods_array['spec_goods_storage'] = $val['spec_goods_storage'];
				}
				$spec_array[$key]	= $val;
			}
		}
        Tpl::output('goods_storage_total',$goods_storage_total);
		/* 当库存为0 直接下架----------- s */
		if ($goods_storage_total == 0 && $goods_array ['goods_show'] != 0) {
			DB::update ( 'goods', array (
					'goods_show' => 0,
					'goods_endtime' => time () 
			), "goods_id='{$goods_array['goods_id']}'" );
		}
		
		$goods_array['goods_spec'] = unserialize($goods_array['goods_spec']);
		$goods_array['spec_name'] = unserialize($goods_array['spec_name']);
		$goods_array['goods_attr'] = unserialize($goods_array['goods_attr']);
		$goods_array['goods_col_img'] = unserialize($goods_array['goods_col_img']);// 规格图片
		
		$model = Model();//该model为公用model实例
		
		//商品受关注次数加1
		$_times = cookie('tm_visit_product');
		if (empty($_times)){
			$model->table('goods')->where(array('goods_id' => $goods_id))->attr('LOW_PRIORITY')->update(array('goods_click' =>array('exp','goods_click+1')));
			setNcCookie('tm_visit_product',1);
			$goods_array['goods_click'] = intval($goods_array['goods_click'])+1;
		}
		Tpl::output('spec_array',$spec_array);
		Tpl::output('spec_count',count($goods_array['goods_spec']));
		Tpl::output('goods_spec', $goods_array['goods_spec']);
		Tpl::output('goods_col_img', $goods_array['goods_col_img']);
		
		//生成缓存的键值
		$hash_key = $goods_array['goods_id'];
		//先查找$hash_key缓存
		$cachekey_arr = array('likenum','sharenum','brand_name');
		if ($_cache = rcache($hash_key,'product')){
			foreach ($_cache as $k=>$v){
				$goods_array[$k] = $v;
			}
		}else {
			//查询SNS中该商品的信息
			$snsgoodsinfo = $model->table('sns_goods')->where(array('snsgoods_goodsid'=>$goods_array['goods_id']))->find();
			$goods_array['likenum'] = $snsgoodsinfo['snsgoods_likenum'];
			$goods_array['sharenum'] = $snsgoodsinfo['snsgoods_sharenum'];

			$data = array();
			if (!empty($goods_array)){
				foreach ($goods_array as $k=>$v){
					if (in_array($k,$cachekey_arr)){
						$data[$k] = $v;
					}
				}
			}
			//缓存商品信息
			wcache($hash_key,$data,'product');
		}
		
		//当前商品收藏会员ID
		$sql = "SELECT member_id FROM #__favorites WHERE fav_id = '$goods_id' AND fav_type = 'goods'";
		$rs = Db::queryAll($sql);
		$m_id = array();
		foreach($rs as $item){
			$m_id[] = $item['member_id'];
		}
		if(isset($_SESSION['member_id'])){
			$is_fav = in_array($_SESSION['member_id'],$m_id);
			Tpl::output('is_fav',$is_fav);
		}

		Tpl::output('m_id',$m_id);
		
        //检查是否为店主本人
        $store_self = false;
        if(!empty($_SESSION['store_id'])) {
            if ($goods_array['store_id'] == $_SESSION['store_id']) {
                $store_self = true;
            }
        }
        Tpl::output('store_self',$store_self);
        
		//验证是否为可加盟品牌
		$brandAllianceModel = new brand_allianceModel();
		$is_alliance_brand = $brandAllianceModel->isAllianceBrand($goods_array['brand_id']);
		$is_alliance_member = $brandAllianceModel->isAllianceMember($_SESSION['member_id'], $goods_array['brand_id']);
		$alliance_info = $brandAllianceModel->getAllianceInfo($_SESSION['member_id'], $goods_array['brand_id']);
		Tpl::output('is_alliance_brand', $is_alliance_brand);
		Tpl::output('is_alliance_member', $is_alliance_member);
		Tpl::output('alliance_info', $alliance_info);
                  $sql = "select * from #__brand_alliance_setting where brand_id = '{$goods_array['brand_id']}'";
                 $brand_alliance_info = Db::queryRow($sql);
                 Tpl::output('brand_alliance_info', $brand_alliance_info);
        
		//评论统计
		$comments = $this->getCommentCount($goods_id,$goods_array['store_id']);
		$c_arr['cc'] = 0;
		foreach($comments as $cv){
			$c_arr['cc'] += $cv;
		}
		if($c_arr['cc'] > 0){
			$c_arr['gcl'] = ($comments['scoreCount1']/$c_arr['cc'])*100;
		}else{
			$c_arr['gcl'] = 0;
		}
		Tpl::output('comments',$c_arr);
		
		//顾客咨询统计
		$consult_count = Db::getCount('consult',"goods_id = '$goods_id'");
		Tpl::output('consult_count',$consult_count);
        
		//商品多图
/*		$image_count = 0;
		$image_str = '';
		if($goods_array['goods_image_more'] == ''){//商品多图与淘宝导入和2.0兼容
			$desc_image	= $model_store_goods->getListImageGoods(array('image_store_id'=>$goods_array['store_id'],'item_id'=>$goods_array['goods_id'],'image_type'=>2));
			$image_key = 0;
			if(!empty($desc_image) && is_array($desc_image)) {//将封面图放到第一位显示
				$goods_image_1	= $goods_array['goods_image'];//封面图
				foreach ($desc_image as $key => $val) {
					if($goods_image_1 == $val['thumb_small']){
						$image_key = $key;break;
					}
				}
				if($image_key > 0) {//将封面图放到第一位显示
					$desc_image_0	= $desc_image[0];
					$desc_image[0]	= $desc_image[$image_key];
					$desc_image[$image_key]	= $desc_image_0;
				}
				foreach ($desc_image as $key => $val) {
					$img = str_replace('_small','_mid',$val['file_thumb']);
					$path = DS.ATTACH_GOODS.DS.$goods_array['store_id'].DS.$img;
					if(is_file(BasePath.$path)){
						$image_str .= SiteUrl.$path.',';
						$image_count++;
					}
				}
				$image_str = rtrim($image_str,',');
			}
		}else{
			$img_list = array();
			$desc_image	= explode(',', $goods_array['goods_image_more']);
			foreach ($desc_image as $key => $val) {
				$img = str_replace('_tiny','_mid',$val);
				$path = DS.ATTACH_GOODS.DS.$goods_array['store_id'].DS.$img;
				if(is_file(BasePath.$path)){
					$image_str .= SiteUrl.$path.',';
					$image_count++;
				}
			}
			$image_str = rtrim($image_str,',');
		}*/

		//商品多图
		$img_list = array();
		if($goods_array['goods_image_more'] == ''){
			$desc_image	= $model_store_goods->getListImageGoods(array('image_store_id'=>$goods_array['store_id'],'item_id'=>$goods_array['goods_id'],'image_type'=>2));
			if(!empty($desc_image) && is_array($desc_image)) {
				foreach ($desc_image as $key => $val) {
					$img = str_replace('_small','_mid',$val['file_thumb']);
					$path = DS.ATTACH_GOODS.DS.$goods_array['store_id'].DS.$img;
					if(is_file(BasePath.$path)){	//如果图片存在使用图片
						$img_list[] = SiteUrl.$path.',';
					}else{
						$img_list[] = TEMPLATES_PATH . '/images/touch2013/no_300_300.jpg';	//如果文件不存在使用默认图片，防止出现图片无法加载影响体验
					}
				}
			}
		}else{
			$desc_image	= explode(',', $goods_array['goods_image_more']);
			foreach ($desc_image as $key => $val) {
				$img = str_replace('_tiny','_mid',$val);
				$path = DS.ATTACH_GOODS.DS.$goods_array['store_id'].DS.$img;
				//$img_list[] = SiteUrl.$path;
				if(is_file(BasePath.$path)){	//如果图片存在使用图片
					$img_list[]= SiteUrl.$path;
				}else{
					$img_list[] = TEMPLATES_PATH . '/images/touch2013/no_300_300.jpg';	//如果文件不存在使用默认图片，防止出现图片无法加载影响体验
				}
			}

		}
        Tpl::output('img_list',$img_list);
		/*如果此商城加入美达通*/
		if($store_info['store_mdt_status'] ==STORE_MDT_STATUS_PASS){
			$model = Model();
			$member_model =new memberModel();
			$member_info = $member_model->infoMember(array('member_id'=>$_SESSION['member_id']));
			$mdt_info =$model->table('mdt')->where(array('province_id'=>$member_info['member_provinceid']))->select();
			if(!empty($mdt_info)){
				//买家注册省份有美达通而且 买卖家不同省份
				if(!empty($mdt_info) && ($goods_array['province_id'] !=$member_info['member_provinceid'])){
					Tpl::output('is_mdt','is_mdt');	
					Tpl::output('mdt_info',$mdt_info[0]);
				}
			}
			//精品超市采用封顶邮费	
			if($goods_array['store_id']==OFFICIAL_STORE_ID){
				$sql="SELECT * FROM #__supermarket_delivery ORDER BY delivery_is_min DESC,delivery_is_mid DESC,delivery_weight ASC,delivery_is_max DESC,delivery_is_excess DESC";
				$rs=db::queryAll($sql);
				Tpl::output('supermarket_delivery',$rs);
			}				
		}
		
		//如果使用运费模板
		if ($goods_array['transport_id'] > 0){
			//取得三种运送方式默认运费
			$model_transport =new transportModel();
			$transport = $model_transport->find($goods_array['transport_id']);
			$extend = $model_transport->getExtendList(array('transport_id'=>$goods_array['transport_id'],'is_default'=>1));
			if (!empty($extend) && is_array($extend)){
				foreach ($extend as $v) {
					if($transport['calculation_method']==0){
						$goods_array[$v['type']."_price"] = $v['sprice'];
					}else if($transport['calculation_method']==1){
						$sumWeight = $goods_array['goods_weight'];//商品总重量
						$outWeight = $sumWeight - $v['snum'];//超出首重量
						if($outWeight>0){
							$xnum = ceil($outWeight/$v['xnum']);//续重次数
							$goods_array[$v['type']."_price"] = $v['sprice']+($xnum*$v['xprice']);
						}else{
							$goods_array[$v['type']."_price"] = $v['sprice'];
						}
					}else if($transport['calculation_method']==2){
						$sumVolume = $goods_array['goods_volume'];//商品总体积
						$outVolume = $sumVolume - $v['snum'];//超出首体积
						if($outVolume>0){
							$xnum = ceil($outVolume/$v['xnum']);//续体积次数
							$goods_array[$v['type']."_price"] = $v['sprice']+($xnum*$v['xprice']);
						}else{
							$goods_array[$v['type']."_price"] = $v['sprice'];
						}
					}
					//$goods_array[$v['type']."_price"] = $v['sprice'];
				}
			}
		}
        // 取此商城所有商品的平均分 ！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
        $sql = "SELECT goods_quality_scores,package_quality_scores,shipping_speed_scores,after_sale_scores FROM #__evaluate_order_goods WHERE ogeval_storeid=" . $goods_array ['store_id'];
        $this_store_goods_score = db::queryAll ( $sql );
        if (! empty ( $this_store_goods_score )) {
            $this_store_goods_avg_score = storeModel::array_avg ( $this_store_goods_score );
            $store_info ['goods_quality_credit'] = ceil ( $this_store_goods_avg_score ['goods_quality_scores'] );
            $store_info ['package_quality_credit'] = ceil ( $this_store_goods_avg_score ['package_quality_scores'] );
            $store_info ['shipping_speed_credit'] = ceil ( $this_store_goods_avg_score ['shipping_speed_scores'] );
            $store_info ['after_sale_credit'] = ceil ( $this_store_goods_avg_score ['after_sale_scores'] );
        }
        
                //九块邮商品关联精品超市商品处理 Start
                  if( ($goods_array['store_id'] == JKY_STORE_ID) && !empty($goods_array['goods_serial']) ){
                      $goods_serial = str_replace('(L)', '', $goods_array['goods_serial']);
                      $sql = "SELECT goods_id FROM #__goods_spec WHERE spec_goods_serial = '$goods_serial'";
                      $relation_goods_id = Db::queryOne($sql);
                      Tpl::output('relation_goods_id',$relation_goods_id);
                  }
                  //九块邮商品关联精品超市商品处理 End

        // 双十活动开始
        $starttoday = strtotime(date('Y-m-d H:i:s',mktime(0,0,0,date('10'),date('10'),date('Y'))));
		$endtoday = strtotime(date('Y-m-d H:i:s',mktime(23,59,59,date('10'),date('10'),date('Y'))));
		if(time()>=$starttoday && time()<= $endtoday){
	        //一元抢最多只能购买1件
	        $buyLog=goodsModel::getActiviteGoods($goods_array['goods_id'],$_SESSION['member_id']);  
	        if($goods_array['goods_activite_flag']==GOODS_ACTIVITE_FLAG_ONEROB) {
	        	$goods_array['spec_goods_storage']=1-$buyLog['buy_num'];
	        	Tpl::output ( 'goods_activite_name', '一元抢' );
	        }
	        //半价购最多只能购买5件 
	        if($goods_array['goods_activite_flag']==GOODS_ACTIVITE_FLAG_HALF) {
	        	$goods_array['spec_goods_storage']=$goods_array['spec_goods_storage']<5?$goods_array['spec_goods_storage']:(5-$buyLog['buy_num']);
	        	Tpl::output ( 'goods_activite_name', '半价购' );
	        }  	
		}

		if((time()<$starttoday || time()> $endtoday) && $goods_array['goods_activite_flag']!=GOODS_ACTIVITE_FLAG_NORMAL){
			$goods_array['spec_goods_storage']=0;
		}
        // 双十活动结束
        
		Tpl::output('store_info',$store_info);
		Tpl::output('goods',$goods_array);
		Tpl::output('goods_image',$desc_image[0]);
		Tpl::output('image_count',$image_count);
		Tpl::output('desc_image',$image_str);
		
		//输出一级地区
		$area_list = array (1 => '北京',2 => '天津',3 => '河北',4 => '山西',5 => '内蒙古',6 => '辽宁',7 => '吉林',8 => '黑龙江',9 => '上海',10 => '江苏',11 => '浙江',12 => '安徽',13 => '福建',14 => '江西',15 => '山东',16 => '河南',17 => '湖北',18 => '湖南',19 => '广东',20 => '广西',21 => '海南',22 => '重庆',23 => '四川',24 => '贵州',25 => '云南',26 => '西藏',27 => '陕西',28 => '甘肃',29 => '青海',30 => '宁夏',31 => '新疆',32 => '台湾',33 => '香港',34 => '澳门',35 => '海外');
		Tpl::output('area_list',$area_list);

		
		//根据买家用户信息所在地区展示在相应地区展示的商品-市级-省级
		if(isset($_SESSION['is_login']) && (int)$_SESSION['is_login'] == 1){
			$member = Model('member')->infoMember(array('member_id'=>(int)$_SESSION['member_id']));
			$area_info = preg_split('/\t/', $member['member_areainfo'],-1,PREG_SPLIT_NO_EMPTY);
			if(count($area_info)==1){
				$param['show_in_province_ids'] = (int)$member['member_provinceid'];
			}elseif(count($area_info)==2 || count($area_info)==3){
				$param['show_in_city_ids'] = (int)$member['member_cityid'];
			}
		}
		if($member['store_id']==$goods_array['store_id']){
			unset($param['show_in_province_ids']);
			unset($param['show_in_city_ids']);
		}
		$param['store_id'] = $goods_array['store_id'];
		$param['goods_id_diff'] = intval($_GET['goods_id']);
		$param['goods_show'] = 1;
		$param['goods_state']	= 0;
		$param['goods_commend'] = 1;
		$param['limit'] = 20;
		$param['order'] = 'goods_id desc';
		//优先得到推荐商品
		$goods_commend_list = $model_store_goods->getGoods($param,'','','goods');

		Tpl::output('goods_commend',$goods_commend_list);

		/**
		 * 生成浏览过产品的cookie
		 */
		$cookievalue = $goods_id.'-'.$goods_array['store_id'];
		if(cookie('viewed_goods')){
			$string_viewed_goods = cookie('viewed_goods');
			if (get_magic_quotes_gpc()) $string_viewed_goods = stripslashes($string_viewed_goods);//去除斜杠
			$vg_ca = @unserialize($string_viewed_goods);
			$sign = true;
			if(!empty($vg_ca) && is_array($vg_ca)){
				foreach ($vg_ca as $vk=>$vv){
					if($vv == $cookievalue){
						$sign = false;
					}
				}
			}else{
				$vg_ca = array();
			}
				
			if($sign){
				if(count($vg_ca) >= 4){
					$vg_ca[]  = $cookievalue;
					array_shift($vg_ca);
				}else{
					$vg_ca[]  = $cookievalue;
				}				
			}
		}else{
			$vg_ca[]  = $cookievalue;
		}
		$vg_ca = serialize($vg_ca);	
        setNcCookie('viewed_goods',$vg_ca);
		//echo '<pre>';print_r(unserialize(cookie('cart')));die;
        //团购活动
        $group_flag = FALSE;
        if(intval($goods_array['group_flag']) === 1) {
            $group_list = $this->get_group_list($goods_id);
            if(!empty($group_list) && is_array($group_list)) {
                $current_time = time();
                foreach($group_list as $group) {
                    if(intval($group['start_time']) < $current_time && intval($group['end_time']) > $current_time) {
                        if(intval($group['state']) === 3) {
                            if($group['def_quantity'] < $group['max_num']) {
                                $group_flag = TRUE;
                                Tpl::output('group_info',$group);
                                break;
                            }
                        }
                    }
                }
            } else {
                //没有新的团购活动，取消商品团购标志
                $model_store_goods->updateGoods(array('group_flag'=>0),$goods_id); 
            }
        }
        Tpl::output('group_flag',$group_flag);

        //限时折扣
        $xianshi_flag = FALSE;
        $start_flag = FALSE;
        $goods_xianshi_flag = FALSE;
        if(intval($GLOBALS['setting_config']['promotion_allow']) === 1){
            if(!$group_flag && intval($goods_array['xianshi_flag']) === 1) {
                $xianshi_goods = $this->get_xianshi_goods($goods_id);  
                if(!empty($xianshi_goods) && intval($xianshi_goods['state']) === self::XIANSHI_GOODS_STATE_NORMAL ) {
                    $xianshi_id = $xianshi_goods['xianshi_id'];
                    $model_xianshi =new p_xianshiModel();
                    $xianshi_info = $model_xianshi->getOne($xianshi_id);
                    if(!empty($xianshi_info)) {
                        if(intval($xianshi_info['state']) === self::XIANSHI_STATE_PUBLISHED) {
                            $current_time = time();
                            if(intval($xianshi_info['end_time']) > $current_time) {
                                $xianshi_flag = TRUE;
                                if(intval($xianshi_info['start_time']) < $current_time) {
                                    $start_flag = TRUE;
                                }
                                Tpl::output('xianshi_info',$xianshi_info);
                                $xianshi_goods['discount'] /= 10;
                                Tpl::output('xianshi_goods',$xianshi_goods);
                            }
                            else {
                                //更新过期限时折扣状态
                                $model_xianshi->update(array('state'=>self::XIANSHI_STATE_END),array('xianshi_id'=>$xianshi_id));
                                $goods_xianshi_flag = TRUE;
                            }
                        }
                        else {
                            $goods_xianshi_flag = TRUE;
                        }
                    }
                } else {
                    $goods_xianshi_flag = TRUE;
                }
            }
        } else {
            if(intval($goods_array['xianshi_flag']) === 1) {
                $goods_xianshi_flag = TRUE;
            }
        }

        //没有限时折扣活动，取消限时折扣标志
        if($goods_xianshi_flag) { 
            $model_store_goods->updateGoods(array('xianshi_flag'=>0),$goods_id); 
        }
		//秒杀条件
		$time=time();
        $miaosha_flag = FALSE;
        if((!$goods_array['group_flag']) &&(intval($goods_array['xianshi_flag']) === 0)&&($goods_array['miaosha_flag']==1)) {
			$miaosha_info['miaosha_price'] = ncPriceFormat($goods_array['miaosha_price']);;
            $miaosha_info['miaosha_flag'] = $miaosha_flag= TRUE;
			//未开始:2, 进行中:1, 已结束:3
			$miaosha_status = 1;
			if($goods_array['miaosha_starttime'] > $time){
				$miaosha_status = 2;
			}elseif($time >$goods_array['miaosha_endtime']){
				$miaosha_status = 3;
				$miaosha_info['miaosha_flag'] = $miaosha_flag= FALSE;
				Db::update ( 'goods', array (
						'miaosha_flag' => 0
				), "goods_id='{$goods_array['goods_id']}'" );
			}
			$miaosha_info['miaosha_status'] = $miaosha_status;
			$miaosha_info['miaosha_starttime'] = $goods_array['miaosha_starttime'] ;
			$miaosha_info['miaosha_endtime'] = $goods_array['miaosha_endtime'];
			Tpl::output ( 'miaosha_info', $miaosha_info );
        }
        Tpl::output('xianshi_flag',$xianshi_flag);
        Tpl::output('start_flag',$start_flag);
		Tpl::output ( 'miaosha_flag', $miaosha_flag );

        //如果不是团购和限时折扣输出满就送活动
        if(intval($GLOBALS['setting_config']['promotion_allow']) === 1){
            if($group_flag || $xianshi_flag) {
                Tpl::output('mansong_flag',FALSE);
            }
            else {
                $this->output_mansong($goods_array['store_id']);
            }
        } else {
            Tpl::output('mansong_flag',FALSE);
        }

        Tpl::output('page','goods');
        // x虚拟销量
        $sql="SELECT count(geval_id) FROM #__evaluate_goods WHERE geval_goodsid=".$_GET['goods_id'];
        $comments_num =DB::queryOne($sql);
        Tpl::output('comments_num',$comments_num);
        $sales_num=$goods_array['lastcomsales'];
        Tpl::output('sales_num',$sales_num);

        Tpl::output('is_give_points',memberModel::is_give_points());
 		$seo_param = array();
		$seo_param['name'] = $goods_array['goods_name'];
		$seo_param['key']  = $goods_array['goods_keywords'];
		$seo_param['description'] = $goods_array['goods_description'];
		Model('seo')->type('product')->param($seo_param)->show();
        if($goods_array['is_color_paste'] == 1 && count($goods_array['goods_spec']) == 1 ){
            Tpl::showpage('goods_paste');
        }else{
            Tpl::showpage ( 'goods' );
        }
	}
    /**
     * 获取团购列表 
     **/
    private function get_group_list($goods_id) {
        $current_time = time();
        $model_group =new goods_groupModel();
        $param = array();
        $param['goods_id'] = $goods_id;
        $param['state'] = 3;
        $param['less_than_end_time'] = $current_time;
        return $model_group->getList($param);
    }
    /**
     * 获取限时折扣商品
     **/
    private function get_xianshi_goods($goods_id) {

        $model_xianshi_goods =new p_xianshi_goodsModel();
        $param = array();
        $param['goods_id'] = $goods_id;
        $param['order'] = 'xianshi_goods_id desc';
        $param['limit'] = 1;
        $xianshi_goods = $model_xianshi_goods->getList($param);
        return $xianshi_goods[0];
    }
    /**
     * 输出满就送活动
     **/
    private function output_mansong($store_id) {

        $model_mansong =new p_mansongModel();
        $param = array();
        $param['state'] = self::MANSONG_STATE_PUBLISHED;
        $current_time = time();
        $param['greater_than_start_time'] = $current_time;
        $param['less_than_end_time'] = $current_time;
        $param['store_id'] = $store_id;
        $param['limit'] = 1;
        $mansong_list = $model_mansong->getList($param);
        $mansong = $mansong_list[0];
        $mansong_flag = FALSE;
        if(!empty($mansong)) {
            $model_mansong_rule =new p_mansong_ruleModel();
            $mansong_rule = $model_mansong_rule->getList(array('mansong_id'=>$mansong['mansong_id'],'order'=>'level asc'));
            if(!empty($mansong_rule)) {
                $mansong_flag = TRUE;
                Tpl::output('mansong_info',$mansong);
                Tpl::output('mansong_rule',$mansong_rule);
            }
        }
        Tpl::output('mansong_flag',$mansong_flag);
    }

    /**
	 * 商品评论
	 */
	public function commentsOp() {
		$goods_id = intval($_GET['goods_id']);
		if ($goods_id <= 0){
			echo json_encode(array('state'=>false));exit;
		}
		//查询商品信息
		$goods_model =new goodsModel();
		$goods_info = $goods_model->getOne($goods_id);
		if (empty($goods_info)){
			echo json_encode(array('state'=>false));exit;
		}
		$where = '';
		//评价等级默认评语
		$evaluate_defaulttext = array('1'=>'非常满意','0'=>'满意','-1'=>'一般');
		//评价等级
		if($_GET['evalscore']){
			switch($_GET['evalscore']){
				case 1:
					$where .= ' AND eg.geval_scores = 1';
					break;
				case 2:
					$where .= ' AND eg.geval_scores = 0';
					break;
				case 3:
					$where .= ' AND eg.geval_scores = -1';
					break;
			}
		}
		$where .= " AND eg.geval_goodsid = $goods_id";
		$where .= " AND eg.geval_storeid = {$goods_info['store_id']}";
		$where .= " AND eg.geval_type = 1";
		$where .= " AND eg.geval_state = 0";
		$where .= ' AND eg.geval_showtime <= '.time();
		$sql = "SELECT eg.*,m.* FROM #__evaluate_goods as eg LEFT JOIN #__member as m ON eg.geval_frommemberid=m.member_id WHERE 1 $where";
		$pageSize = 20;
        $curPage = (int)$_GET['curpage'];
		$rs = Db::PageQuery($sql,$curPage,$pageSize);
		$goodsevallist = $rs->fetchAll();
		//分页
		$page	= new Page();
		$page->setEachNum($pageSize);
		$page->setNowPage($curPage);
        $page->setTotalNum($rs->pageRows());
		$page->setStyle('admin');
		$page->setTotalPage();

		//评论关键词词典      获取评论中的关键词  关键词->规范词 凡是差评词，请在value后面加逗号
		$keyList = array('质量不错'=>'质量好','划算'=>'性价比高','服务好'=>'态度好','速度快'=>'物流很快','效果一般'=>'效果一般,','效果很好'=>'效果好','物流差'=>'物流慢','正品'=>'质量保障','发货快'=>'物流快',
						'宝贝不错'=>'质量好','好评'=>'满意','不错'=>'满意','客服服务非常好'=>'客服服务态度好,','第一次'=>'第一次','性价比高'=>'性价比高','热心'=>'客服服务好','好货'=>'产品质量好','顾客很满意'=>'满意',
						'值得信赖'=>'值得信赖','下次还会来'=>'宝贝很棒','顾客喜欢'=>'顾客喜欢','发货及时'=>'物流快','还行'=>'宝贝不错','浓度不错'=>'浓度高','货到付款'=>'货到付款','还行'=>'宝贝不错',
						'物流很快'=>'物流快','很喜欢'=>'很喜欢','贴心'=>'贴心','不伤头发'=>'不伤头发','太惊喜'=>'惊喜','还不错'=>'质量好','差评'=>'差评,','没有臭味'=>'无异味','好'=>'满意','商品质量很好'=>'质量好',
						'态度好'=>'服务态度好','用着不错'=>'质量不错','量很足'=>'实惠','服务周到'=>'服务好','正品'=>'正品','物美价廉'=>'物美价廉','发货神速'=>'发货速度快','发货很快'=>'发货快','非常棒'=>'服务好','很好'=>'好评');
		$getKeyWord = array();

		$info = array();
		if (!empty($goodsevallist)){
			foreach ($goodsevallist as $k=>$v){					
				//处理评论内容的显示
				if ($v['geval_content'] == '' || $v['geval_state'] == '1'){
					$v['geval_content'] = $evaluate_defaulttext[$v['geval_scores']];
				}
				switch ($v['geval_scores']){
					case 1:
						$v['geval_scoressign'] = '100';
						break;
					case 0:
						$v['geval_scoressign'] = '80';
						break;
					case -1:
						$v['geval_scoressign'] = '60';
						break;
				}
				$v['geval_addtime'] = date('Y-m-d',$v['geval_addtime']);
				//买家信用
				$v['credit_arr'] = getCreditArr(intval($v['member_credit']));
				//显示匿名
				$v['geval_frommembername'] = $v['geval_isanonymous'] == 1?str_cut($v['geval_frommembername'],2).'***':$v['geval_frommembername'];
				$goodsevallist[$k] = $v;

				foreach($keyList as $worKey =>$wordVal){
					if(strpos($v['geval_content'],$worKey) > -1){
						$getKeyWord[] = $wordVal;
					}
				}
			}


			$commentCountMap = $this->getCommentCount($goods_id,$goods_info['store_id']);
			$info['commentCountMap'] = $commentCountMap;
			$info['comments'] = $goodsevallist;
			$info['state'] = true;
			$info['commentCount'] = $page->getTotalNum();
			$info['curpage'] = $curPage;
			$info['totalPage'] = $page->getTotalPage();
			$info['keyword'] = array_unique($getKeyWord);
			echo json_encode($info);exit;
		}else{
			echo json_encode(array('state'=>false));exit;
		}
	}
	
	/**
	 * 产品咨询
	 */
	public function cosultingOp() {
		$goods_id	 = intval($_GET['goods_id']);
		if($goods_id <= 0){
			echo json_encode(array('state'=>false));
			exit;
		}
		$sql = "SELECT * FROM #__consult WHERE goods_id = '$goods_id'";
		$pageSize = 20;
        $curPage = (int)$_GET['curpage'];
		$rs = Db::PageQuery($sql,$curPage,$pageSize);
		$consult_list = $rs->fetchAll();
		//分页
		$page	= new Page();
		$page->setEachNum($pageSize);
		$page->setNowPage($curPage);
        $page->setTotalNum($rs->pageRows());
		$page->setStyle('admin');
		$page->setTotalPage();
		
		if(!empty($consult_list) && is_array($consult_list)){
			foreach($consult_list as $k=>$v){
				if($v['member_id'] == 0){
					$consult_list[$k]['cmember_name'] = '游客';
				}
				if($v['isanonymous'] == 1){
					$consult_list[$k]['cmember_name'] = str_cut($v['cmember_name'],2).'**';
				}
				$consult_list[$k]['consult_addtime'] = date('Y-m-d H:i:s',$v['consult_addtime']); 
			}
			$info['consult_list'] = $consult_list;
			$info['state'] = true;
			$info['totalCount'] = $page->getTotalNum();
			$info['curpage'] = $curPage;
			$info['totalPage'] = $page->getTotalPage();
			echo json_encode($info);exit;
		}else{
			echo json_encode(array('state'=>false));
			exit;
		}
	}
	/**
	 * 商品咨询添加
	 */
	public function save_consultajaxOp(){
		//检查是否可以评论
        if(!C('guest_comment') && !$_SESSION['member_id']){
        	echo json_encode(array('done'=>'false','msg'=>Language::get('goods_index_goods_noallow')));
        	die;
        }
		$goods_id	 = intval($_GET['goods_id']);
		if($goods_id <= 0){
			echo json_encode(array('done'=>'false','msg'=>Language::get('wrong_argument')));
        	die;
		}
		//咨询内容的非空验证
		if(trim($_GET['goods_content'])== ""){
			echo json_encode(array('done'=>'false','msg'=>Language::get('goods_index_input_consult')));
        	die;
		}
		//验证码验证
		if(C('captcha_status_goodsqa') == '1' && !checkSeccode($_GET['nchash'],$_GET['captcha'])){
			echo json_encode(array('done'=>'false','msg'=>Language::get('wrong_checkcode')));
        	die;
		}
        if (check_repeat('comment')){
        	echo json_encode(array('done'=>'false','msg'=>Language::get('nc_common_op_repeat')));
        	die;
        }		
        if($_SESSION['member_id']){
	        //查询会员信息
	        $member_model =new memberModel();
	        $member_info = $member_model->infoMember(array('member_id'=>"{$_SESSION['member_id']}"));
			if(empty($member_info) || $member_info['is_allowtalk'] == 0){
	        	echo json_encode(array('done'=>'false','msg'=>Language::get('goods_index_goods_noallow')));
        		die;
	        }
        }
		//判断商品编号的存在性和合法性
        $goods_info	=goodsModel::getGoodsRowByGoodsID($goods_id);
		if(empty($goods_info)){
			echo json_encode(array('done'=>'false','msg'=>Language::get('goods_index_goods_not_exists')));
        	die;
		}
        //判断是否是店主本人
        if($_SESSION['store_id'] && $goods_info['store_id'] == $_SESSION['store_id']) {
            echo json_encode(array('done'=>'false','msg'=>Language::get('goods_index_consult_store_error')));
        	die;
        }
		//检查商城状态
		$store_model =new storeModel();
		$store_info	= $store_model->shopStore(array('store_id'=>"{$goods_info['store_id']}"));
		if($store_info['store_state'] == '0' || intval($store_info['store_state']) == '2' || (intval($store_info['store_end_time']) != 0 && $store_info['store_end_time'] <= time())){
			echo json_encode(array('done'=>'false','msg'=>Language::get('goods_index_goods_store_closed')));
        	die;
		}
		//接收数据并保存
		$input	= array();
		$input['goods_id']			= $goods_id;
		$input['cgoods_name']		= $goods_info['goods_name'];
		$input['member_id']			= intval($_SESSION['member_id']) > 0?$_SESSION['member_id']:0;
		$input['cmember_name']		= $_SESSION['member_name']?$_SESSION['member_name']:'';
		$input['seller_id']			= $store_info['member_id'];
		$input['email']				= $_GET['email'];
		if (strtoupper(CHARSET) == 'GBK') {
			$input['consult_content']	= Language::getGBK($_GET['goods_content']);
		}else{
			$input['consult_content']	= $_GET['goods_content'];
		}
		$input['isanonymous']		= $_GET['hide_name']=='hide'?1:0;
		$consult_model	=new consultModel();
		if($consult_model->addConsult($input)){
			echo json_encode(array('done'=>'true'));
        	die; 
		}else{
			echo json_encode(array('done'=>'false','msg'=>Language::get('goods_index_consult_fail')));
        	die; 
		}
	}
	/**
	 * 异步显示组合销售
	 */
	public function get_bundlingOp(){
		$goods_id = intval($_GET['goods_id']);
		$store_id = intval($_GET['id']);
		if($goods_id <= 0 || $store_id <= 0){
			exit;
		}
		// 实力化模型
		$model = Model();
		
		// 更新组合销售状态
		$update = array();
		$update['bl_quota_state']	= '0';
		$model->table('p_bundling_quota')->where('store_id='.$store_id.' and bl_quota_endtime<'.time())->update($update);
		
		// 查询商城套餐活动是否开启
		$quota_list = $model->table('p_bundling_quota')->where('store_id='.$store_id.' and bl_quota_state=1')->select();
		if(!empty($quota_list)){
			
			// 根据商品id查询bl_id
			$b_g_list = $model->table('p_bundling_goods')->field('bl_id')->where('goods_id='.$goods_id)->select();
	
			if(!empty($b_g_list) && is_array($b_g_list)){
				$b_id_array = array();
				foreach ($b_g_list as $val){
					$b_id_array[] = $val['bl_id'];
				}
				
				// 查询套餐列表
				$bundling_list	= $model->table('p_bundling')->where('bl_id in ('.implode(',', $b_id_array).') and bl_state=1')->select();
				// 整理
				if(!empty($bundling_list) && is_array($bundling_list)){
					$bundling_array = array();
					foreach ($bundling_list as $val){
						$bundling_array[$val['bl_id']]['id']		= $val['bl_id'];
						$bundling_array[$val['bl_id']]['name']		= $val['bl_name'];
						$bundling_array[$val['bl_id']]['cost_price']= 0;
						$bundling_array[$val['bl_id']]['price']		= $val['bl_discount_price'];
					}
				}
	
				// 查询商品列表
				$b_goods_list	= $model->table('p_bundling_goods,goods')
										->field('p_bundling_goods.bl_goods_id, p_bundling_goods.bl_id, p_bundling_goods.goods_id, p_bundling_goods.goods_name, goods.goods_image, goods.goods_store_price, goods.store_id')
										->join('inner')->on('p_bundling_goods.goods_id=goods.goods_id')
										->where('bl_id in ('.implode(',', $b_id_array).') and goods_show=1')->select();
				// 整理
				if(!empty($b_goods_list) && is_array($b_goods_list)){
					$b_goods_array	= array();
					foreach($b_goods_list as $val){
						$k = intval($val['goods_id']) == $goods_id?0:$val['goods_id'];
						$b_goods_array[$val['bl_id']][$k]['id']		= $val['goods_id'];
						$b_goods_array[$val['bl_id']][$k]['image']	= $val['goods_image'];
						$b_goods_array[$val['bl_id']][$k]['price']	= $val['goods_store_price'];
						$b_goods_array[$val['bl_id']][$k]['name']		= $val['goods_name'];
						$b_goods_array[$val['bl_id']][$k]['store_id']	= $val['store_id'];
						$bundling_array[$val['bl_id']]['cost_price']	+= intval($val['goods_store_price']);
					}
				}
				
				Tpl::output('bundling_array', $bundling_array);
				Tpl::output('b_goods_array', $b_goods_array);
			}
		}
		Tpl::showpage('goods_bundling','null_layout');
	}
	/**
	 * 商品详细页运费显示
	 *
	 * @return unknown
	 */
	function calcOp(){
		if (!is_numeric($_GET['id']) || !is_numeric($_GET['tid'])) return false;
		$weight = $_GET['weight'];
		$volume = $_GET['volume'];
		$quantity = $_GET['quantity'];
		$model_transport =new transportModel();
//		$extend = $model_transport->getExtendList(array('transport_id'=>array(intval($_GET['tid'])),'top_area_id'=>intval($_GET['id'])));
		$transport = $model_transport->find(intval($_GET['tid']));
		$extend = $model_transport->getExtendList(array('transport_id'=>array(intval($_GET['tid']))));
		if (!empty($extend) && is_array($extend)){
			$calc = array();
			$calc_default = array();
			foreach ($extend as $v) {
				if (strpos($v['top_area_id'],",".intval($_GET['id']).",") !== false){
					
					if($transport['calculation_method']==0){
						$outNum = $quantity-$v['snum'];
						if($outNum>0){
							$xnum = ceil($outNum/$v['xnum']);
							$calc[$v['type']] = ncPriceFormat($v['sprice']+($xnum*$v['xprice']));
						}else{
							$calc[$v['type']] = ncPriceFormat($v['sprice']);
						}
					}else if($transport['calculation_method']==1){
						$sumWeight = $weight*$quantity;//商品总重量
						$outWeight = $sumWeight - $v['snum'];//超出首重量
						if($outWeight>0){
							$xnum = ceil($outWeight/$v['xnum']);//续重次数
							$calc[$v['type']] = ncPriceFormat($v['sprice']+($xnum*$v['xprice']));
						}else{
							$calc[$v['type']] = ncPriceFormat($v['sprice']);
						}
					}else if($transport['calculation_method']==2){
						$sumVolume = $volume*$quantity;//商品总体积
						$outVolume = $sumVolume - $v['snum'];//超出首体积
						if($outVolume>0){
							$xnum = ceil($outVolume/$v['xnum']);//续体积次数
							$calc[$v['type']] = ncPriceFormat($v['sprice']+($xnum*$v['xprice']));
						}else{
							$calc[$v['type']] = ncPriceFormat($v['sprice']);
						}
					}
				}
				if ($v['is_default']==1){	
					if($transport['calculation_method']==0){
						$outNum = $quantity-$v['snum'];
						if($outNum>0){
							$xnum = ceil($outNum/$v['xnum']);
							$calc_default[$v['type']] = ncPriceFormat($v['sprice']+($xnum*$v['xprice']));
						}else{
							$calc_default[$v['type']] = ncPriceFormat($v['sprice']);
						}
					}else if($transport['calculation_method']==1){
						$sumWeight = $weight*$quantity;//商品总重量
						$outWeight = $sumWeight - $v['snum'];//超出首重量
						if($outWeight>0){
							$xnum = ceil($outWeight/$v['xnum']);//续重次数
							$calc_default[$v['type']] = ncPriceFormat($v['sprice']+($xnum*$v['xprice']));
						}else{
							$calc_default[$v['type']] = ncPriceFormat($v['sprice']);
						}
					}else if($transport['calculation_method']==2){
						$sumVolume = $volume*$quantity;//商品总体积
						$outVolume = $sumVolume - $v['snum'];//超出首体积
						if($outVolume>0){
							$xnum = ceil($outVolume/$v['xnum']);//续体积次数
							$calc_default[$v['type']] = ncPriceFormat($v['sprice']+($xnum*$v['xprice']));
						}else{
							$calc_default[$v['type']] = ncPriceFormat($v['sprice']);
						}
					}
				}
			}
			//如果运费模板中没有指定该地区，取默认运费
			foreach (array('py','kd','es') as $v){
				if (!isset($calc[$v]) && isset($calc_default[$v])){
					$calc[$v] = $calc_default[$v];
				}
			}
		}
		echo json_encode($calc);
	}
	
	/**
	 * 显示规格属性
	 */
	function get_s_aOp(){
		if(!is_numeric($_GET['goods_id']) || !is_numeric($_GET['id'])) die('null');

		$model	= Model();
		$goods_info		= $model->table('goods')->field('spec_name, goods_spec, goods_attr, goods_col_img')->find($_GET['goods_id']);
		
		if(C('spec_model') == 1){
			$spec_name	= unserialize($goods_info['spec_name']);
			if(!empty($spec_name) && is_array($spec_name)){
				$k = array();
				foreach($spec_name as $key=>$val){
					$k[] = $key;
				}
				if (!empty($k)) $return = $model->table('spec')->field('sp_id, sp_name')->select(implode(',', $k));
				if(!empty($return) && is_array($return)){
					foreach ($return as $val){
						if(isset($spec_name[$val['sp_id']])) $spec_name[$val['sp_id']] = $val['sp_name'];
					}
				}
			}
			
			$goods_spec = unserialize($goods_info['goods_spec']);
			if(!empty($goods_spec) && is_array($goods_spec)){
				$k = array();
				foreach ($goods_spec as $value){
					if(!empty($value) && is_array($value)){
						foreach ($value as $key=>$val){
							$k[] = $key;
						}
					}
				}
				if (!empty($k)) $return = $model->table('spec_value')->field('sp_value_id, sp_value_name, sp_id')->select(implode(',', $k));
				if(!empty($return) && is_array($return)){
					foreach ($return as $val){
						if(isset($goods_spec[$val['sp_id']][$val['sp_value_id']])) $goods_spec[$val['sp_id']][$val['sp_value_id']] = array('name'=>$val['sp_value_name'],'id'=>$val['sp_value_id']);
					}
				}
			}
			
			$goods_col_img = unserialize($goods_info['goods_col_img']);
		}else{
			$spec_name		= 'null';
			$goods_spec		= 'null';
			$goods_col_img	= 'null';
		}
		
		$goods_attr	= unserialize($goods_info['goods_attr']);
		if(!empty($goods_attr) && is_array($goods_attr)){
			$k = array();
			foreach ($goods_attr as &$value){
				if(!empty($value) && is_array($value)){
					foreach ($value as $key=>$val){
						if(is_numeric($key)) $k[] = $key;
					}
				}
			}
			if (!empty($k)) $return = $model->table('attribute_value,attribute')->join('inner')->on('attribute_value.attr_id=attribute.attr_id')->field('attr_value_id, attr_value_name,attribute_value.attr_id, attr_name')->where('attr_value_id in ('.implode(',', $k).')')->select();
			if(!empty($return) && is_array($return)){
				foreach ($return as $key=>$val){
					if(isset($goods_attr[$val['attr_id']]))$goods_attrs[$val['attr_id']] = array('name'=>$val['attr_name'],'value'=>$val['attr_value_name']);
				}
			}else{
				$goods_attrs = 'null';
			}
		}
		
		$data['spec_name']		= $spec_name;
		$data['goods_spec']		= $goods_spec;
		$data['goods_attr']		= $goods_attrs;
		$data['goods_col_img']	= $goods_col_img?$goods_col_img:'null';
		
		
		/**
		 * 转码
		 */
		if (strtoupper(CHARSET) == 'GBK'){
			$data = Language::getUTF8($data);
		}
		echo json_encode($data);
	}
	/**
	 * 到货通知填写
	 */
	function daohuo_noticeOp(){
		$goods_id = intval($_GET['goods_id']);
		if(isset($_POST['goods_id'])){
			
			$daohuo_email = trim($_POST['daohuo_email'])?trim($_POST['daohuo_email']):'';
			$daohuo_phone = trim($_POST['daohuo_phone'])?trim($_POST['daohuo_phone']):'';
			$goods_id = trim($_POST['goods_id'])?trim($_POST['goods_id']):'';
			if(!$daohuo_email && !$daohuo_phone){mobileJump('请至少填写一个通知方式');}
				
			if($daohuo_email &&  !preg_match('/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i', $daohuo_email)){
				mobileJump('邮箱格式错误');
			}
			if($daohuo_phone &&  !preg_match('/^(13|14|15|18|17)\d{9}$/i', $daohuo_phone)){
				mobileJump('手机号格式错误');
			}
				
			$data = array();
			$data['goods_id'] = $goods_id;
			$data['email'] = $daohuo_email;
			$data['phone'] = $daohuo_phone;
			$data['add_time'] = time();
			Db::insert("daohuo_notice" ,$data);
			mobileJump('提交成功', "index.php?act=goods&goods_id=".$goods_id);
		}
		Tpl::output("goods_id" ,$goods_id);
		Tpl::showpage('goods_daohuo_notice');
	}
    /*
    * 在点击秒杀按扭，还没有下定单就将goods表中的miaosha_storage提前减少1，这样如果下了定单后,不对秒杀库存减少
    * */
    public function miaosha_ajax2Op(){
        $goods_id = $_GET['goods_id'];
        $sql = "select miaosha_storage from #__goods where goods_id='$goods_id'";
        $miaosha_storage_row = Db::queryRow($sql);
        if($miaosha_storage_row['miaosha_storage']>0){
            $miaosha_storage_new = $miaosha_storage_row['miaosha_storage']-1;
        }else{
            $miaosha_storage_new = 0;
        }
        Db::update('goods',array('miaosha_storage'=>$miaosha_storage_new),"goods_id='$goods_id'");
    }
}